<?php
class index extends Page {

	public $page_title = 'Mit nézel?';
	public $layout = "skeleton";

	public function load(){

		browserReqRedirect("/unsupported_browser");

		$this->html->name = 'main';
		//$this->html->cache = false;
		$this->include_fb = true;
		$this->html->link('defaultpointytip', array('options' => array('id' => 'defaultPointyTipStyle')));

		$this->html->link(array('css-reset', 'style_new', 'fauxSelect'));

		$this->html->mootools(array(
			'Request.HTML',
			'Request.JSON',
			'Lang',
			'Form.Validator.Inline',
			'Assets',
			'Tips',
			'Tips.Pointy',
			'MooScroller',
			'Autocompleter.Observer',
			'Form.Validator.Tips',
			'Form.Validator.Hungarian',
			'Fx.Move',
			'Fx.Reveal',
			'Fx.Scroll',
			'Fx.Transitions',
			'Fx.Elements',
			'Fx.Tween',
			'Color',
			'Drag.Move',
			'Log',
			'Spinner',
			'Date.Hungarian',
			'Keyboard',
			'Keyboard.Extras',
			'URI',
			'LazyLoad',
			'Cookie',
			'Form.Request'
		), "jsmin");

		$this->html->js(array(
			'sprintf',
			'moocheck',
			'fauxSelect',
			'rank.class',
			'common',
			'script',
			'series_page'
		), array('compress' => true));

		//$this->html->js('excanvas_r43', array('conditional' => 'IE', 'compress' => false, 'inside' => true));
		$this->html->link('iefix', array('conditional' => 'IE'));

		$this->statistics();

		$rv = new reviews;
		$recentReviews = $rv->recentReviews();

		$this->template->assign('recentReviews', $recentReviews);
	}

	private function statistics(){
		$tv = new TheTvDB;
		$ps = $tv->mostPopularSeries();

		if (!empty($ps)) {
    		$max = $ps[0]['hits'];
    		foreach($ps as &$item){
    			$item['percent'] = round(($item['hits']/$max) * 100);
    		}
		} else {
		    $ps = array();
		}

		$this->template->assign('popular_series', $ps);

		$rank = new rank;
		$rnk = $rank->getMostlyRankedEpisodes();
		$this->template->assign('mostly_ranked_eps', $rnk);
	}

}

?>